#ifndef __THREADPOOL_HEADERFILE__
#define __THREADPOOL_HEADERFILE__
/* header file */
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <pthread.h>
#include <sys/types.h>
#include <math.h>
#include <sys/stat.h>
#include <semaphore.h>
#include "bufferqueue_02.h"

/* macro definition */
#define PAGESIZE    4096
#define NTHREAD     4
#define MISSION_LIMIT 16

/* type declaration  */
enum thread_status{T_DEAD=-1, T_FREE, T_ALIVE};
enum threadpool_status{P_SHUTDOWN = -1, P_RUNNING = 1};
enum task_priority{URGENT, COMMON, IGNORE};
typedef struct {
    void* (*routine)(void*);
    void* args;
    const char* info;    
}thread_task_t;

typedef struct {
    pthread_t       tid;
    thread_task_t   task;
    enum thread_status status;
}thread_t;


typedef struct threadpool{
    thread_t*    threads;
    size_t      capacity;
    size_t      size;
    size_t      alive_size;

    bufque_t       mission_que;
    
    pthread_mutex_t     threads_lock;

    int (*submit_task)  (struct threadpool*, thread_task_t*);
}threadpool_t;


/* variable definition  */
/* function declaration */
int tpool_init(threadpool_t* tpool, size_t start_threadnum); 
int tpool_destroy(threadpool_t* tpool);
#endif
